exports.getInfo = function(req, res) {
  function getRemoteAddr(req, res) {
    return req.headers['x-forwarded-for'] ||
      req.ip ||
      req._remoteAddress ||
      (req.socket &&
        (req.socket.remoteAddress ||
          (req.socket.socket && req.socket.socket.remoteAddress)
        )
      )
  }

  function getUserAgent(res, req) {
    return req.headers['user-agent'];
  }

  function getContentLength(res, req) {
    return (res._headers && res._headers['content-length']) ||
      (res.__headers && res.__headers['Content-Length']) ||
      '-'
  }

  var result = {};
  result.url = req.originalUrl || req.url;
  result.protocol = req.protocol;
  result.protocol = req.protocol;
  result.hostname = req.hostname;
  result.method = req.method;
  result.status = res.__statusCode || res.statusCode;
  result.responseTime = res.responseTime;
  result.date = new Date().toUTCString();
  result.referrer = req.headers.referer || req.headers.referrer || '';
  result.userAgent = getUserAgent(res, req);
  return result;
}


exports.formatTime = function(time, tpl =
  "{year}{month}{day}{hour}{minute}{second}") {

  function _formatTime(date) {
    return {
      year: date.getUTCFullYear(),
      month: (date.getUTCMonth() + 1) < 10 ? "0" + (date.getUTCMonth() + 1) : date
        .getUTCMonth() +
        1,
      day: date.getUTCDate() < 10 ? "0" + date.getDate() : date.getDate(),
      hour: date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
      minute: date.getUTCMinutes() < 10 ? "0" + date.getUTCMinutes() : date.getUTCMinutes(),
      second: date.getUTCSeconds() < 10 ? "0" + date.getUTCSeconds() : date.getUTCSeconds(),
      millisecond: date.getUTCMilliseconds() < 10 ? "0" + date.getUTCMilliseconds() : date
        .getUTCMilliseconds()
    };
  }
  let tmpDate;
  if (time) {
    tmpDate = new Date(time);
  } else {
    tmpDate = new Date();
  }
  let between = _formatTime(tmpDate)
  return tpl.replace(/{(\w*)}/g, function(m, key) {
    return between.hasOwnProperty(key) ? between[key] : "";
  });
}
